package com.onlinesys.service.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.onlinesys.beans.LeftMenu;
import com.onlinesys.database.DBManager;
import com.onlinesys.service.LeftMenuService;

public class LeftMenuServiceImpl implements LeftMenuService {
    @Override
    public List<LeftMenu> getLeftMenus(String modules) throws SQLException {
        List<LeftMenu> menus = new ArrayList<LeftMenu>();
        String sql = "SELECT id, name, url, seq, icon FROM modules WHERE id in (" + modules +" ) ORDER BY seq";
        Connection conn = DBManager.getDBConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            LeftMenu lm = new LeftMenu();
            lm.setId(rs.getInt("id"));
            lm.setName(rs.getString("name"));
            lm.setUrl(rs.getString("url"));
            lm.setOrder(rs.getInt("seq"));
            lm.setIcon(rs.getString("icon"));
            menus.add(lm);
        }
        rs.close();
        stmt.close();
        conn.close();
        return menus;
    }
}
